package com.ngc.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ngc.mall.bo.Spec;
import com.ngc.mall.domain.SkuDomain;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SkuMapper extends BaseMapper<SkuDomain> {
    @Select("select * from sku where id in #{idList}")
    List<SkuDomain> findSkuByIdList(List<Long> idList);

    @Update("update sku set stock=stock-#{count}  where id=#{id} and stock > #{count}")
    Boolean reduceSkuStock(Long id,Integer count);

    @Select("select * from sku_spec where sku_id=#{skuId}")
    List<Spec> findSpecsBySkuId(Long skuId);

    @Update("update sku set stock=stock+#{count} where id=#{id}")
    Boolean recoverStock(Long id,Integer count);

}
